import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_app_demo/base/color/common_color.dart';

import 'common_click_widget.dart';

/// A custom AppBar widget designed for consistent styling across the app.
///
/// Created by wangliang on 2025/3/24.
class CommonAppBar extends AppBar {
  /// Creates a [CommonAppBar].
  ///
  /// Parameters:
  /// - [key]: An optional key to identify this widget.
  /// - [showLeading]: Determines whether to show a leading widget (typically a back button). Defaults to true.
  /// - [onBackPressed]: A callback function to be executed when the leading widget is tapped.
  ///   If null and [showLeading] is true, a default back button will be shown.
  /// - [title]: The title text to be displayed in the app bar. Defaults to an empty string.
  /// - [actions]: A list of widgets to be displayed on the right side of the app bar.
  /// - [elevation]: The elevation of the app bar. Defaults to 0.
  /// - [backgroundColor]: The background color of the app bar. Defaults to white.
  /// - [statusBarColor]: The color of the status bar. Defaults to transparent.
  CommonAppBar({
    Key? key,
    bool showLeading = true,
    VoidCallback? onBackPressed,
    String title = '',
    List<Widget>? actions,
    double? elevation = 0,
    Color? backgroundColor = Colors.white,
    Color? statusBarColor = Colors.transparent,
    bool leadingNeedPressColor = true,
  }) : super(
          key: key,
          leading: showLeading
              ? CommonClickWidget(
                  needPressColor: leadingNeedPressColor,
                  onTap: () => onBackPressed?.call(),
                  child: Container(
                    padding: const EdgeInsets.only(left: 12),
                    alignment: Alignment.centerLeft,
                    child: Image.asset('assets/images/common_black_left_arrow.png'),
                  ),
                )
              : null,
          automaticallyImplyLeading: showLeading,
          title: Text(
            title,
            style: TextStyle(fontSize: 16, color: CommonColor.std001, fontWeight: FontWeight.w500),
          ),
          toolbarHeight: 44,
          backgroundColor: backgroundColor,
          foregroundColor: CommonColor.std001,
          systemOverlayStyle: SystemUiOverlayStyle.light.copyWith(
            statusBarColor: statusBarColor,
            statusBarBrightness: Brightness.light,
            statusBarIconBrightness: Brightness.dark,
            systemNavigationBarColor: Colors.white,
            systemNavigationBarIconBrightness: Brightness.dark,
          ),
          elevation: elevation,
          centerTitle: true,
          actions: actions,
        );
}
